package com.tools.ad.store;

import android.content.Context;
import android.content.SharedPreferences;

import com.hm.base.android.mob.store.SharedPrefManager;
import com.tools.ad.ADConstant;

/**
 * desc:
 * date: 2017/12/19 15:34
 * author: ancun
 */
public class ADSharedPrefManager extends SharedPrefManager {

    // 配置信息
    private static final String AD_PREF = "ad_config_pref";

    // 配置
    private SharedPreferences adPref;

    public ADSharedPrefManager(Context context) {
        super(context);
        adPref = context.getSharedPreferences(AD_PREF, Context.MODE_PRIVATE);
    }

    public long getLastShowTime(String lastShowTimeKey) {
        return adPref.getLong(lastShowTimeKey, 0);
    }

    public void setLastShowTime(String lastShowTimeKey, long lastShowTime) {
        SharedPreferences.Editor editor = adPref.edit();
        editor.putLong(lastShowTimeKey, lastShowTime);
        editor.apply();
    }

    public int getShowCounts(String showCountKey) {
        return adPref.getInt(showCountKey, 0);
    }

    public void setShowCounts(String showCountKey, int count) {
        SharedPreferences.Editor editor = adPref.edit();
        editor.putInt(showCountKey, count);
        editor.apply();
    }

    public long getBeginTimeOfDay(String beginTimeOfDayKey) {
        return adPref.getLong(beginTimeOfDayKey, 0);
    }

    public void setBeginTimeOfDay(String beginTimeOfDayKey, long beginTime) {
        SharedPreferences.Editor editor = adPref.edit();
        editor.putLong(beginTimeOfDayKey, beginTime);
        editor.apply();
    }

    /**
     * 设置应用外全屏广告的开关
     *
     * @param enable
     */
    public void setAppOuterAdEnable(boolean enable) {
        SharedPreferences.Editor editor = adPref.edit();
        editor.putBoolean(ADConstant.AdSharedPrefKey.KEY_APP_OUTER_AD, enable).apply();
    }

    /**
     * 获取应用外全屏广告的开关
     *
     * @return
     */
    public boolean getAppOuterAdEnable() {
        return adPref.getBoolean(ADConstant.AdSharedPrefKey.KEY_APP_OUTER_AD, true);
    }

    /**
     * 设置自动清理弹窗广告的开关
     *
     * @param enable
     */
    public void setAutoCleanAdEnable(boolean enable) {
        SharedPreferences.Editor editor = adPref.edit();
        editor.putBoolean(ADConstant.AdSharedPrefKey.KEY_AUTO_CLEAN_AD, enable).apply();
    }

    /**
     * 获取自动清理弹窗广告的开关
     *
     * @return
     */
    public boolean getAutoCleanAdEnable() {
        return adPref.getBoolean(ADConstant.AdSharedPrefKey.KEY_AUTO_CLEAN_AD, false);
    }

    /**
     * 设置快滑功能（广告）的开关
     *
     * @param enable
     */
    public void setSwipeAdEnable(boolean enable) {
        SharedPreferences.Editor editor = adPref.edit();
        editor.putBoolean(ADConstant.AdSharedPrefKey.KEY_SWIPE_AD, enable).apply();
    }

    /**
     * 获取快滑功能（广告）的开关
     * 默认开
     *
     * @return
     */
    public boolean getSwipeAdEnable() {
        return adPref.getBoolean(ADConstant.AdSharedPrefKey.KEY_SWIPE_AD, true);
    }

}
